﻿using System;
using StardewModdingAPI;
using StardewModdingAPI.Events;
using StardewValley;

namespace WorseGame.Content
{
    public class 体力限制进食(IMonitor monitor, IModHelper helper)
    {
        private readonly IMonitor 监视器 = monitor;
        private readonly IModHelper 助手 = helper;

        public void Initialize()
        {
            助手.Events.Input.ButtonPressed += 检测食物使用;
        }

        private void 检测食物使用(object? sender, ButtonPressedEventArgs e)
        {
            if (!Context.IsWorldReady) return;
            if (e.Button != SButton.MouseRight) return;
            var 玩家 = Game1.player;
            var 物品 = (StardewValley.Object)玩家.CurrentItem;
            if (物品 != null && 物品.Edibility > 0)
            {
                int 食物回复量 = (int)(物品.Edibility * 2.5);
                float 当前体力 = 玩家.stamina;
                float 最大体力 = 玩家.MaxStamina;
                if (当前体力 + 食物回复量 > 最大体力)
                {
                    Game1.playSound("cancel");
                    助手.Input.Suppress(e.Button);
                }
            }
        }
    }
}